
<template>
  <view class="page">
    <!-- 地址列表 -->
    <view class="address-list">
      <view class="list" v-for="(item,index) in addressinfo" :key="index" >
        <view class="name-phone" @click="on(item.id)">
          <view class="name">
            <text class="one-omit">{{item.name}}</text>
          </view>
          <view class="phone">
            <text>{{item.phone}}</text>
            <text class="tag" v-if="item.isDefault">默认</text>
            <text class="tag blue">{{item.title}}</text>
          </view>
        </view>
        <view class="address-edit">
          <view class="address">
            <text>{{item.address}}</text>
          </view>
          <view class="edit" @click.stop="onAddressEdit(1,item.id,item.phone,item.address,item.name,item.region,item.title,item.isDefault)">
            <text class="iconfont icon-edit1"></text>
          </view>
          <view class="edit" @click="onDel(item.id)">
            <text class="iconfont icon-close1"></text>
          </view>
        </view>
      </view>
    </view>
    <!-- 添加地址 -->
    <view class="add-address">
      <view class="btn" @click="onAddressEdit(2,null)">
        <text>新建收货地址</text>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        addressinfo:''
      };
    },
    onShow(){
      uni.request({
        data: {
			// this.$queue.getData("id")
          userId:1,
        },
        method: 'POST',
        header: {
          "content-type": 'application/x-www-form-urlencoded'
        },
        url: "http://localhost:8089/cgoAdmin/loadAddressList",
        success: (res) => {
          this.addressinfo=res.data.result;
          
        }
      });
    },
    methods:{
      onDel(id){
        uni.request({
          data: {
            id:id
          },
          method: 'POST',
          header: {
            "content-type": 'application/x-www-form-urlencoded'
          },
          url: "http://localhost:8089/cgoAdmin/delAddressList",
          success: (res) => {
            if(res.data.success){
              this.$queue.showToast("删除成功")
              uni.navigateTo({
                url:'/pages/AddressList/AddressList'
              })({
                delta:-1
              })
            }
          }
        });
      },
      /**
       * 编辑地址点击
       */
      onAddressEdit(type,id,phone,address,name,region,title,isDefault){
        uni.navigateTo({
          
          url: '/pages/AddressEdit/AddressEdit?type=' + type+"&phone="
          +phone+"&address="+address+"&name="+name+"&region="+region+"&title="
          +title+"&isDefault="+isDefault+"&id="+id
        })
      },
	  on(id){
		   this.$router.push({path: "/pages/ConfirmOrder/ConfirmOrder", query: {addId: id}})
	  }
    }
  }
</script>

<style scoped lang="scss">
  @import 'AddressList.scss';
</style>
